package com.systemframework.pay.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author summer
 * @date 2023-06-06 16:16
 */
@Configuration

public class AliPayConfiguration {

  private  AliPayProperties aliPayProperties;

  @Autowired
  public void setAliPayProperties(AliPayProperties aliPayProperties) {
    this.aliPayProperties = aliPayProperties;
  }

  @Bean
  public AlipayClient alipayClient() throws AlipayApiException {
    AlipayConfig alipayConfig = new AlipayConfig();
    alipayConfig.setAppId(aliPayProperties.getAppId());
    alipayConfig.setAlipayPublicKey(aliPayProperties.getAlipayPublicKey());
    alipayConfig.setPrivateKey(aliPayProperties.getPrivateKey());
    return new DefaultAlipayClient(alipayConfig);
  }

}
